import { ApiTrack } from '../core';
import { ApiTrackConfig } from '../types';
import { collector } from '../plugins/collector';
import { Reporter } from './reporter';

export * from '../core';
export * from '../types';

let apitrack: ApiTrack;
export let reporter: Reporter;

export function creatApiTrack({ customReporter, ...config }: ApiTrackConfig) {
  reporter = new Reporter({
    biz_id: config.biz_id,
    env: config?.isOnline ? 'online' : config.env || 'other',
    options: customReporter,
  });
  apitrack = new ApiTrack({ ...config, reporter });
  apitrack.use(collector);
  return apitrack;
}

export const track: typeof apitrack.track = (...args) => {
  return apitrack?.track?.(...args);
};
export const addRules: typeof apitrack.addRules = (...args) => {
  return apitrack?.addRules?.(...args);
};
